<?php
namespace app\manage\controller;
obj('api/Api')->isSession('manage_system','index.php?r=manage/login/index');
class  setController extends \app\base\controller\BaseController
{

	public function index(){

		if(!IS_POST){
			$this->pagetext=array("基础设置","网站设置");
			include CONFIG_PATH . 'siteconfig.php';
			$this->ret=$Siteinfo;
		    $this->display();
		}else{
		 $sitename=$_POST['sitename'];
		 $hosturl=$_POST['hosturl'];
		 $logo=$_POST['logo'];
		 $pid=$_POST['pid'];
		 $appkey=$_POST['appkey'];
		 $secretKey=$_POST['secretKey'];
		  $apiurl=$_POST['apiurl'];
		  $code=$_POST['code'];
		 $zhuan=$_POST['zhuan'];
     $os=$_POST['os'];
     $tongji=htmlspecialchars($_POST['tongji']);
         $content="<?php
         \r\n\$Siteinfo=array(
              'sitename'=>'{$sitename}',
              'hosturl'=>'{$hosturl}',
              'logo'=>'{$logo}',
              'pid'=>'{$pid}',
			   'appkey'=>'{$appkey}',
			    'secretKey'=>'{$secretKey}',
				'apiurl'=>'{$apiurl}',
				'code'=>'{$code}',
              'zhuan'=>'{$zhuan}',
              'os'=>'{$os}',
              'tongji'=>'{$tongji}',

        );";
           $of = fopen(CONFIG_PATH . 'siteconfig.php', 'w');
              if ($of) {
                  fwrite($of, $content);
              }
              fclose($of);
              echo json_encode(array("info" => "设置成功", "status" => "y"));
		}

	}

	public function url(){

		if(!IS_POST){
			$this->pagetext=array("基础设置","自定义rul");

			include CONFIG_PATH . 'rule.php';
			$keys=array_keys($rule['REWRITE_RULE']);




			$this->DEBUG=$rule['DEBUG'];
			$this->REWRITE_ON=$rule['REWRITE_ON'];
			$this->moren=$rule['moren'];
			$this->ret=$keys;

		    $this->display();
		}else{

			$DEBUG=$_POST['DEBUG'];
			$REWRITE_ON=$_POST['REWRITE_ON'];
			$moren=$_POST['moren'];

			 $content="<?php
       \r\n\$rule=array(
       'ENV' => 'global',                      //调试配置文件名
    'DEBUG' =>{$DEBUG},                             //是否显示详细错误信息
    'LOG_ON' => false,                           //错误日志记录，需要自己扩展appHook
    'LOG_PATH' => ROOT_PATH . 'data/log/',       //日志记录目录
    'TIMEZONE'=> 'PRC',                          //时间区域
	 'moren' => '".$moren."',                       //默认首页访问模块
    'REWRITE_ON' => {$REWRITE_ON},                       //伪静态开关，需要放入对应环境的伪静态规则

     'REWRITE_RULE' => array(
      'index.html'=>'index/index/index',
		'gift.html'=>'plug/gift/index',
        'gift-view-<id>.html'=>'plug/gift/view/id=<id>',
        'search-<key>.html'=>'plug/gift/search/key=<key>',
        'gift-page-<id>.html'=>'plug/gift/page/id=<id>',
        /************gift rule **************/
        'topiclist-<id>-<type>.html'=>'plug/gift/topiclist/id=<id>/type=<type>',
        'topic.html'=>'plug/gift/topic',
        'findgift.html'=>'plug/gift/findgift',
        'findgift-category-<id>.html'=>'plug/gift/findgift/id=<id>',
        'e_404.html'=>'plug/gift/e_404',
        'mylike.html'=>'plug/gift/mylike',
        'strategy.html'=>'plug/gift/strategy',
        'strategy-<id>-<type>.html'=>'plug/gift/strategy/id=<id>/type=<type>',
        'strategy-view-<id>-html'=>'plug/gift/strategy_view/id=<id>',
        'question.html'=>'plug/gift/question',
        'question-category-<id>.html'=>'plug/gift/question/id=<id>',
        'question-view-<id>.html'=>'plug/gift/questionview/id=<id>',
        'm-gift.html'=>'plug/mgift/index',
        'm-gift-strategy-view-<id>.html'=>'plug/mgift/strategy_view/id=<id>',
        'm-gift-find.html'=>'plug/mgift/find',
        'm-gift-find-category-<id>.html'=>'plug/mgift/find/id=<id>',
        'm-gift-findgiftlist-category-<id>.html'=>'plug/mgift/findgift/id=<id>',
        'm-gift-giftview-<id>.html'=>'plug/mgift/giftview/id=<id>',
        'm-gift-strategy.html'=>'plug/mgift/strategy',
        'm-gift-strategy-<id>-<type>.html'=>'plug/mgift/strategy/id=<id>/type=<type>',
        'm-gift-strategy-<id>.html'=>'plug/mgift/strategyview/id=<id>',
        'm-gift-ask.html'=>'plug/mgift/ask',
        'm-gift-ask-list-<id>.html'=>'plug/mgift/asklist/id=<id>',
        'm-gift-ask-view-<id>.html'=>'plug/mgift/askview/id=<id>',
        'm-searchindex.html'=>'plug/mgift/searchindex',
        'm-search-<key>.html'=>'plug/mgift/search/key=<key>',
		'gotb.html'=>'go/tb/itemiid',
		'goto.html'=>'go/to/url',
		 'china-list-<list>.html'=>'index/index/index/list=<list>',
        'china-mall-<mall>.html'=>'index/index/index/mall=<mall>',
        'china-<list>-<mall>.html'=>'index/index/index/list=<list>/mall=<mall>',
        'haitao.html'=>'index/haitao/index',
        'haitao-list-<list>.html'=>'index/haitao/index/list=<list>',
        'haitao-mall-<mall>.html'=>'index/haitao/index/mall=<mall>',
        'haitao-<list>-<mall>.html'=>'index/haitao/index/list=<list>/mall=<mall>',
        'rank.html'=>'index/rank/index',
        'rank-<time>.html'=>'index/rank/index/time=<time>',
        'cheaps.html'=>'index/cheaps/index',
        'cheaps-<id>.html'=>'index/cheaps/index/id=<id>',
        'view-<id>.html'=>'index/view/index/id=<id>',
        'so-<key>.html'=>'index/search/index/key=<key>',
		'so.html'=>'index/search/index',
        'hot.html'=>'index/hot/index',
        'boss.html'=>'index/boss/index',
		'page-<id>.html'=>'index/page/index/id=<id>',
        'go-<id>.html'=>'index/go/index',
        'm.html'=>'index/m/index',
        'm-view-<id>.html'=>'index/m/view/id=<id>',
        'm-search-<key>.html'=>'index/m/search/key=<key>'

    ),
      );
       ";
	  $of = fopen(CONFIG_PATH . 'rule.php', 'w');
            if ($of) {
                fwrite($of, $content);
            }
            fclose($of);

       echo json_encode(array("info" => "设置成功", "status" => "y"));
     


		}
	}


	public function seo(){

		if(!IS_POST){
			$this->pagetext=array("基础设置","SEO设置");
			include CONFIG_PATH . 'seo.php';
			$this->ret=$SEO;
			$this->display();
			exit;
		}else{
      $index_title=$_POST['index_title'];
      $index_keywords=$_POST['index_keywords'];
      $index_dec=$_POST['index_dec'];
      $ht_title=$_POST['ht_title'];
      $ht_short_title=$_POST['ht_short_title'];
      $ht_keywords=$_POST['ht_keywords'];
      $ht_dec=$_POST['ht_dec'];
      $rank_title=$_POST['rank_title'];
      $rank_keywords=$_POST['rank_keywords'];
      $cheaps_dec=$_POST['cheaps_dec'];
      $banquan=$_POST['banquan'];
	  $about=$_POST['about'];
	  $beian=$_POST['beian'];
     
			 $content="<?php
       \r\n\$SEO=array(
              'index_title'=>'{$index_title}',
              'index_keywords'=>'{$index_keywords}',
              'index_dec'=>'{$index_dec}',
              'ht_title'=>'{$ht_title}',
              'ht_short_title'=>'{$ht_short_title}',
              'ht_keywords'=>'{$ht_keywords}',
              'ht_dec'=>'{$ht_dec}',
              'rank_title'=>'{$rank_title}',
              'frank_keywords'=>'{$rank_keywords}',
              'cheaps_dec'=>'{$cheaps_dec}',
              'banquan'=>'{$banquan}',
              'about'=>'{$about}',
              'beian'=>'{$beian}'



        );";

        $of = fopen(CONFIG_PATH . 'seo.php', 'w');
            if ($of) {
                fwrite($of, $content);
            }
            fclose($of);

       echo json_encode(array("info" => "设置成功", "status" => "y"));

		}
	}


   public function api(){

      if(!IS_POST){
        $this->pagetext=array("基础设置","生成高佣API");
        include CONFIG_PATH . 'apiset.php';
        $this->ret=$api;
        $this->display();
        exit;
      }else{


        $appKey=$_POST['appKey'];
		$appSecret=$_POST['appSecret'];
		$Apikey=$_POST['Apikey'];
		$app_key=$_POST['app_key'];
		$app_secret=$_POST['app_secret'];
		 $siteid=$_POST['siteid'];
        $hash=$_POST['hash'];
       $content="<?php
       \r\n\$api=array(
              'appKey'=>'{$appKey}',
			  'appSecret'=>'{$appSecret}',
			   'Apikey'=>'{$Apikey}',
			    'app_key'=>'{$app_key}',
				 'app_secret'=>'{$app_secret}',
			    'siteid'=>'{$siteid}',
              'hash'=>'{$hash}',
        );";

        $of = fopen(CONFIG_PATH . 'apiset.php', 'w');
            if ($of) {
                fwrite($of, $content);
            }
            fclose($of);

       echo json_encode(array("info" => "设置成功", "status" => "y"));

      }
   }

    public function sms(){

      if(!IS_POST){
        $this->pagetext=array("基础设置","短信通道");
        include CONFIG_PATH . 'sms.php';
        $this->ret=$sms;
        $this->display();
        exit;
      }else{

        $smsurl=$_POST['smsurl'];
        $reg_sms=$_POST['reg_sms'];
       $content="<?php
       \r\n\$sms=array(
            'smsurl'=>'{$smsurl}',
            'reg_sms'=>'{$reg_sms}',
      );";

        $of = fopen(CONFIG_PATH . 'sms.php', 'w');
            if ($of) {
                fwrite($of, $content);
            }
            fclose($of);

       echo json_encode(array("info" => "设置成功", "status" => "y"));

      }
   }

}